/*
 * CustomerAction.java
 * 
 * Created on 02/10/2007, 12:43:14 PM
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.actions;

import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.bean.ActaReunion;

import model.bean.Asamblea;
import model.bean.AsistenteAsamblea;
import model.bean.Mocion;
import model.factory.RecreacionalFactory;
import model.service.ActaReunionService;
import model.service.AsambleaService;
import model.service.AsistenteAsambleaService;
import model.service.MocionService;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import view.common.struts.CustomActionForm;
import view.common.Constants;

import view.common.struts.CustomDispatchAction;

/**
 * @Archivo LoginAction.java
 * @Fecha                @Autor   @Cambios
 * 21/01/2011 02:35:29 PM       moshiro
 */
public class ActaReunionAction extends CustomDispatchAction {

    private final static String PRINCIPAL = "principal";
    private final static String REGISTRAR = "registrar";
    private final static String MODIFICAR = "modificar";
    private final static String LISTAR = "listar";

    @Override
    public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) throws Exception {
        CustomActionForm frm = (CustomActionForm) form;
        ActaReunion beanSearch = new ActaReunion();
        frm.setBeanSearch(beanSearch);
        frm.setBeanList(getActaReunionService().listarActaReunion(beanSearch));
        frm.setMapList(new HashMap());
        return mapping.findForward(PRINCIPAL);
    }

    public ActionForward consultar(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) throws Exception {
        CustomActionForm frm = (CustomActionForm) form;
        ActaReunion beanSearch = (ActaReunion) frm.getBeanSearch();
        frm.setBeanList(getActaReunionService().listarActaReunion(beanSearch));
        return mapping.findForward(PRINCIPAL);
    }

    public ActionForward refrescar(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) throws Exception {
        return mapping.findForward(PRINCIPAL);
    }

    public ActionForward registrar(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) throws Exception {
        CustomActionForm frm = (CustomActionForm) form;
        ActaReunion bean = new ActaReunion();
        frm.setBean(bean);
        Asamblea filtro = new Asamblea();
        filtro.setEstado(Constants.ESTADO_FINALIZADO);
        frm.getMapList().put("asambleaList", getAsambleaService().listarAsamblea(filtro));
        return mapping.findForward(REGISTRAR);
    }

    public ActionForward eliminar(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) throws Exception {
        CustomActionForm frm = (CustomActionForm) form;
        getActaReunionService().eliminarActaReunion(Long.valueOf(frm.getSelectedIndex()));
        return unspecified(mapping, form, req, resp);
    }

    public ActionForward modificar(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) throws Exception {
        CustomActionForm frm = (CustomActionForm) form;
        ActaReunion beanSelected = new ActaReunion(Long.valueOf(frm.getSelectedIndex()));
        ActaReunion bean = getActaReunionService().obtenerActaReunion(beanSelected);
        frm.setBean(bean);
        return mapping.findForward(MODIFICAR);
    }

    public ActionForward cerrar(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) throws Exception {
        CustomActionForm frm = (CustomActionForm) form;
        getActaReunionService().cerrarActaReunion(Long.valueOf(frm.getSelectedIndex()));
        return unspecified(mapping, form, req, resp);
    }

    public ActionForward listar(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) throws Exception {
        CustomActionForm frm = (CustomActionForm) form;
        ActaReunion beanSelected = new ActaReunion(Long.valueOf(frm.getSelectedIndex()));
        ActaReunion bean = getActaReunionService().obtenerActaReunion(beanSelected);
        frm.setBean(bean);

        AsistenteAsamblea filtro = new AsistenteAsamblea();
        filtro.setAsamblea(new Asamblea(bean.getAsamblea().getCodigo()));
        frm.setFormFileList(getAsistenteAsambleaService().listarAsistenteAsamblea(filtro));

        Mocion mocion = new Mocion();
        mocion.setAsamblea(new Asamblea(bean.getAsamblea().getCodigo()));
        frm.setBeanList(getMocionService().listarMocion(mocion));
        return mapping.findForward(LISTAR);
    }

    public ActionForward guardar(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) throws Exception {
        CustomActionForm frm = (CustomActionForm) form;
        ActaReunion bean = (ActaReunion) frm.getBean();

        if (bean.getCodigo() == null) {
            //INSERTAR
            getActaReunionService().agregarActaReunion(bean);
        } else {
            //MODIFICAR
            getActaReunionService().modificarActaReunion(bean);
        }
        return unspecified(mapping, form, req, resp);
    }

    public ActaReunionService getActaReunionService() {
        return RecreacionalFactory.getInstance().getActaReunionService();
    }

    public AsambleaService getAsambleaService() {
        return RecreacionalFactory.getInstance().getAsambleaService();
    }

    public AsistenteAsambleaService getAsistenteAsambleaService() {
        return RecreacionalFactory.getInstance().getAsistenteAsambleaService();
    }

    public MocionService getMocionService() {
        return RecreacionalFactory.getInstance().getMocionService();
    }
}
